package com.eastedu.report.controller;


import com.eastedu.report.common.model.parameter.ReportExportParameter;
import com.eastedu.report.service.PrincipalMonthlyReportService;
import com.eastedu.template.model.ReportResult;
import com.eastedu.template.model.SchoolReportFileData;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springdoc.api.annotations.ParameterObject;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

/**
 * 模版管理
 *
 * @author luozhenzhong
 */
@RestController
@RequestMapping(value = "/api/reports", params = {"version=1.0"})
@Tag(name = "报告导出 - 1.0", description = "报告导出 - 1.0")
@Slf4j
public class ReportExportController {

    private final PrincipalMonthlyReportService principalMonthlyReportService;

    /**
     * Instantiates a new Report export controller.
     *
     * @param principalMonthlyReportService the principal monthly report service
     */
    public ReportExportController(PrincipalMonthlyReportService principalMonthlyReportService) {
        this.principalMonthlyReportService = principalMonthlyReportService;
    }


    /**
     * List http entity.
     *
     * @param taskId the task id
     * @return the report result
     * @throws IOException the io exception
     */
    @Operation(summary = "查询校长月报", description = "查询校长月报")
    @GetMapping("principal-monthly-report")
    public ReportResult export(@Parameter(description = "任务ID") String taskId) throws IOException {
        return principalMonthlyReportService.getReport(taskId);
    }


    /**
     * List http entity.
     *
     * @param parameter the parameter
     * @return list
     */
    @Operation(summary = "查询校长月报（包括资源型、生生/混合用户）", description = "查询校长月报（包括资源型、生生/混合用户）")
    @GetMapping("principal-monthly-report-for-compress")
    public SchoolReportFileData getReportForCompress(@Validated @ParameterObject ReportExportParameter parameter) {
        return principalMonthlyReportService.getReportForCompress(parameter);
    }


    /**
     * List http entity.
     *
     * @param parameter the parameter
     * @return list
     */
    @Operation(summary = "生成校长月报", description = "生成校长月报")
    @PostMapping("principal-monthly-report")
    public List<ReportResult> generate(@Validated @ParameterObject ReportExportParameter parameter) {
        return principalMonthlyReportService.generate(parameter);
    }


}
